﻿Imports System.Data.SqlClient

Public Class DataProvider
    Const connection As String = "Server=QuocTri-PC\SQLEXPRESS;Database=QuanLyXeOto;Integrated Security=True"
    Shared cn As SqlConnection
    Shared Function GetCn() As SqlConnection
        cn = New SqlConnection(connection)
        cn.Open()
        Return cn
    End Function

    Shared Sub CloseCn()
        cn.Close()
    End Sub

    Shared Function LoadTable(ByVal _strSQL As String) As DataTable
        Dim cn As New SqlConnection(connection)
        cn.Open()
        Dim da As New SqlDataAdapter(_strSQL, cn)
        da.SelectCommand.CommandType = CommandType.StoredProcedure
        Dim dt As New DataTable
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Shared Sub ExecuteNonQuery(ByVal _strSQL As String)
        Dim cn As New SqlConnection(connection)
        cn.Open()
        Dim cmd As New SqlCommand(_strSQL, cn)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub


End Class
